<?php

namespace app\queue\stomp;

use app\queue\BaseConsumer;
use common\service\DelayOrderTaskStepCategoryConfirmService;
use Throwable;
use Webman\Stomp\RetryAbleConsumer;

/**
 * 延期单环节确认异步处理
 */
class DelayOrderStepCategoryConfirmAsyncConsumer extends BaseConsumer implements RetryAbleConsumer
{

    // 要消费的队列名
    public $queue = 'delay_order_step_category_confirm';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * @param $data
     * @return void
     * @throws Throwable
     */
    public function doConsume($data)
    {
        DelayOrderTaskStepCategoryConfirmService::getInstance()->confirm($data, request()->getUserId());
    }

    /**
     * 重试间隔
     * @return int
     */
    public function getTtr()
    {
        return 60;
    }

    /**
     * 能否重试
     * @param $attempt
     * @param $error
     * @return bool
     */
    public function canRetry($attempt, $error)
    {
        trace(format_exception_info($error), 'ERR');
        return $attempt <= 5;
    }
}
